/*
 * CompleteOrder.java
 *
 * Created on April 5, 2007, 4:57 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.byu.isys413.actions;

import Data.*;
import java.sql.SQLException;
import java.util.List;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.http.*;

/**
 *
 * @author Danny Beutler
 */
public class CompleteOrder implements edu.byu.isys413.web.Action{
    
    /** Creates a new instance of CompleteOrder */
    public CompleteOrder() {
    }
    
    public String process(HttpServletRequest request, HttpServletResponse response) throws Exception {
        HttpSession session = request.getSession();
        //Save the transaction
        
        //Save the transactionLines
        //Save each revenueSource with using the class type factory
        
        //Send an email to the user with the details of the message.
        String host = "gateway.byu.edu";
        String from = "orders@illucient.com";
        CustomerBO customer = (CustomerBO) session.getAttribute("customer");
        //String to = customer.getEmail();
        String to = "dannyb@alianza.com";
        // Get system properties
        Properties props = System.getProperties();
        // Setup mail server
        props.put("mail.smtp.host", host);
        // Get session
        Authenticator auth = new SMTPAuthenticator();
        Session mailSession = Session.getDefaultInstance(props, auth);
        // Define message
        MimeMessage message = new MimeMessage(mailSession);
        // Set the from address
        message.setFrom(new InternetAddress(from));
        // Set the to address
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
        // Set the subject
        message.setSubject("Hello JavaMail");
        // Set the content
         message.setText("Welcome to JavaMail");
        // Send message
         Transport.send(message,message.getAllRecipients());
        
        return "CompleteOrder.jsp";
    }
}
